require.config(window.jshead);
require(['jquery','layer','navigator'], function($,layer) {
    layer.config({
        path: '/js/layer/'
    });
    //发送ajax读取数据
    $.ajax({
        type: "POST",
        url: "/user/info/getInfo",
        data: {},
        dataType: "json",
        success: function (data) {
            $('#education').find("option:selected").text(data.companyAddress);
            //毕业学校
            $('#userschool').val(data.graduatedSchool);
            //婚姻状况
            $('#marry').val(data.maritalStatus)
            //居住地址
            $('#liveAddress').val(data.currentAddress);
            //收货地址
            $('#thingAddress').val(data.shippingAddress);
            //公司行业
            $('#job').find("option:selected").text(data.companyIndustry);
            //公司规模
            $('#job_people').find("option:selected").text(data.companySize);
            //职位
            $('#jobPlay').val(data.position);
            //月收入
            $('#jobGet').val(data.monthlyIncome);
            //是否购房
            $('#has_home').val(data.isBuyHouse);
            //是否购车
            $('#has_car').val(data.isBugCar);
            //紧急联系人姓名
            $('#mergPeople').val(data.emergencyContactPerson);
            //紧急联系人电话
            $('#mergPeoplePhone').val(data.emergencyContactPhone);
            //紧急联系人关系
            $('#emergencyContactRelation').find("option:selected").text(data.emergencyContactRelation);
            $('#userId').html(data.id);
        }
    });



    //对于数据做校验
    $('#jobGet').keyup(function(){
        $('#jobGet').val();
        var aa =   $('#jobGet').val()
        var reg =/^[1-9]*[1-9][0-9]*$/
        if(!reg.test(aa)){
            layer.tips('请输入整数工资','#jobGet');
            $('#jobGet').val('')
        }
    })

    //点击发送数据保存
    $('.information_submit').bind('click',function(){
        //首先校验手机号
        var phone=$('#mergPeoplePhone').val();
        if(phone==""){
            layer.tips("请先输入手机号",'#mergPeoplePhone');
            return;
        }
        if (!/^[1][3,4,5,7,8][0-9]{9}$/.exec(phone)) {
            layer.tips("请输入正确的手机号",'#mergPeoplePhone');
            return;
        }


        //最高学历
        var companyAddress = $('#education').find("option:selected").text();
        //毕业学校
        var graduatedSchool = $('#userschool').val();
        //婚姻状况
        var maritalStatus   = $('#marry').val()
        //居住地址
        var currentAddress = $('#liveAddress').val();
        //收货地址
        var shippingAddress = $('#thingAddress').val();
        //公司行业
        var companyIndustry = $('#job').find("option:selected").text();
        //公司规模
        var companySize = $('#job_people').find("option:selected").text();
        //职位
        var position = $('#jobPlay').val();
        //月收入
        var monthlyIncome = $('#jobGet').val();
        //是否购房
        var isBuyHouse = $('#has_home').val();
        //是否购车
        var isBugCar = $('#has_car').val();
        //紧急联系人姓名
        var emergencyContactPerson = $('#mergPeople').val();
        //紧急联系人电话
        var emergencyContactPhone = $('#mergPeoplePhone').val();
        //紧急联系人关系
        var  emergencyContactRelation = $('#emergencyContactRelation').find("option:selected").text();
        //用户id
        var id =  $('#userId').html();
        $.ajax({
            type:'POST',
            url:'/user/info/modifyInfo',
            data:{
                id:id,
                companyAddress:companyAddress,
                graduatedSchool:graduatedSchool,
                maritalStatus:maritalStatus,
                currentAddress:currentAddress,
                shippingAddress:shippingAddress,
                companyIndustry:companyIndustry,
                companySize:companySize,
                position:position,
                monthlyIncome:monthlyIncome,
                isBuyHouse:isBuyHouse,
                isBugCar:isBugCar,
                emergencyContactPerson:emergencyContactPerson,
                emergencyContactPhone:emergencyContactPhone,
                emergencyContactRelation:emergencyContactRelation
            },
            datatype:'json',
            success:function (data){
                console.log(data)
                if(data.result=='success'){
                    console.log(data)
                    window.location.reload();
                }
            }
        })
    })







});